/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.secretaria.saude.view;

import com.secretaria.saude.dominio.ProcedimentoTabWin;
import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author pablo
 */
public class ButtonRenderer extends JLabel
                           implements TableCellRenderer {
    Border unselectedBorder = null;
    Border selectedBorder = null;
    boolean isBordered = true;

    public ButtonRenderer(boolean isBordered) {
        this.isBordered = isBordered;
        setOpaque(true); //MUST do this for background to show up.
    }

    public Component getTableCellRendererComponent(
                            JTable table, Object procedimentoTabWin,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
        ProcedimentoTabWin newProcedimentoTabWin = (ProcedimentoTabWin) procedimentoTabWin;
        //setBackground(newColor);
        setText(newProcedimentoTabWin != null ? newProcedimentoTabWin.toString() : "");
        if (isBordered) {
            if (isSelected) {
                if (selectedBorder == null) {
                    selectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
                                              table.getSelectionBackground());
                }
                setBorder(selectedBorder);
            } else {
                if (unselectedBorder == null) {
                    unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
                                              table.getBackground());
                }
                setBorder(unselectedBorder);
            }
        }
        
//        setToolTipText("RGB value: " + newColor.getRed() + ", "
//                                     + newColor.getGreen() + ", "
//                                     + newColor.getBlue());
        return this;
    }
    
}
